package admin.util;

import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import jxl.Workbook;
import jxl.write.WritableImage;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

import admin.DTO.ComponentDTO;

public class JfreeChart {
	public void Chart1(int count) throws IOException{
		DefaultPieDataset dataset = new DefaultPieDataset();
		 
		 dataset.setValue("불량률"+count+"개",count); 
		 
		 JFreeChart chart =ChartFactory.createPieChart("Pie Chart", dataset, true, true, false);
		 
		 chart.setBackgroundPaint(java.awt.Color.white);
		 chart.setTitle("월별 DVD 대여량");
		 chart.getTitle().setFont(new Font("돋움",Font.BOLD,20));
		 chart.getLegend().setItemFont(new Font("돋움",Font.PLAIN,10));
		 
		 PiePlot plot = (PiePlot) chart.getPlot();
		 plot.setLabelFont(new Font("돋움", Font.PLAIN, 12));

		 ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection());
		 String fileName2 = "C:\\MES\\img\\" + "K0001.png";
		 ChartUtilities.saveChartAsPNG(new File(fileName2),chart,600,300,info2);
	}
	
	public void Chart2(int count) throws IOException{
		DefaultPieDataset dataset = new DefaultPieDataset();
		 
		 dataset.setValue("성공률"+count+"개",count); 
		 
		 JFreeChart chart =ChartFactory.createPieChart("Pie Chart", dataset, true, true, false);
		 
		 chart.setBackgroundPaint(java.awt.Color.white);
		 chart.setTitle("월별 DVD 대여량");
		 chart.getTitle().setFont(new Font("돋움",Font.BOLD,20));
		 chart.getLegend().setItemFont(new Font("돋움",Font.PLAIN,10));
		 
		 PiePlot plot = (PiePlot) chart.getPlot();
		 plot.setLabelFont(new Font("돋움", Font.PLAIN, 12));

		 ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection());
		 String fileName2 = "C:\\MES\\img\\" + "K0002.png";
		 ChartUtilities.saveChartAsPNG(new File(fileName2),chart,600,300,info2);
	}
	
	public void Chart3(int i, int a) throws IOException{
		DefaultPieDataset dataset = new DefaultPieDataset();
		 
		 dataset.setValue("불량",i); 
		 dataset.setValue("정상", a);
		 
		 JFreeChart chart =ChartFactory.createPieChart("Pie Chart", dataset, true, true, false);
		 
		 chart.setBackgroundPaint(java.awt.Color.white);
		 chart.setTitle("월별 DVD 대여량");
		 chart.getTitle().setFont(new Font("돋움",Font.BOLD,20));
		 chart.getLegend().setItemFont(new Font("돋움",Font.PLAIN,10));
		 
		 PiePlot plot = (PiePlot) chart.getPlot();
		 plot.setLabelFont(new Font("돋움", Font.PLAIN, 12));

		 ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection());
		 String fileName2 = "C:\\MES\\img\\" + "K0003.png";
		 ChartUtilities.saveChartAsPNG(new File(fileName2),chart,600,300,info2);
	}
}
